package agents.interaction;

import extra.Position;
import game.constants.ReferenceAgent;
import game.constants.ReferenceObject;
import game.constants.ReferenceSpecialFeature;
import interfaces.impl.HumanInteraction;
import objects.SpetialFeature;
import objects.WorldObject;
import universe.Universe;
import actions.ActionBuildStarcraftObject;
import actions.ActionXYtoMove;

public class InteractionBuildCommandCenter extends HumanInteraction{
	
	private ActionXYtoMove actionXYtoMove;
	private ActionBuildStarcraftObject actionBuildStarcraftObject;
	
	private Position position;
	
	SpetialFeature commandCentetPrice;
	SpetialFeature attackRange;
	
	SpetialFeature xToMove;
	SpetialFeature yToMove;

	@Override
	public void initializeParametersList() {
		position=new Position();
		addParameter(position);
		
	}

	@Override
	public void initializeActionList() {
		actionXYtoMove= new ActionXYtoMove();
		addAction(actionXYtoMove);
		
		actionBuildStarcraftObject=new ActionBuildStarcraftObject();
		addAction(actionBuildStarcraftObject);
		
	}

	@Override
	public void initializeSpecialFeatures() {
		
		commandCentetPrice= new SpetialFeature(ReferenceSpecialFeature.SPETIAL_FEATURE_COMMAND_CENTER_PRICE);
		addSpetialFeature(commandCentetPrice);
		
		attackRange= new SpetialFeature(ReferenceSpecialFeature.SPETIAL_FEATURE_ATTACK_RANGE);
		addSpetialFeature(attackRange);
		
		xToMove = new SpetialFeature(ReferenceSpecialFeature.SPETIAL_FEATURE_X_TO_MOVE);
		addSpetialFeature(xToMove);
		
		yToMove = new SpetialFeature(ReferenceSpecialFeature.SPETIAL_FEATURE_Y_TO_MOVE);
		addSpetialFeature(yToMove);
		
		
	}

	@Override
	public void initializeName() {
		name="Build Command Center";
		
	}

	@Override
	public void initializeId() {
		id=ReferenceAgent.AGENT_HUMAN_INTERACTION_BUILD_COMMAND_CENTER;
		
	}

	@Override
	public void updateChild(WorldObject object, Universe universe, double time) {
		
		object.desactivateAllHumanInteractions();
		isActive=true;
		
		double distance = (Position.DistanceBetween(object.getPosition(), position));
		
		if(distance>attackRange.getValue()){
			if(xToMove.getValue()==position.getX() && yToMove.getValue()==position.getY()){
				return;
			}
			actionXYtoMove.setSource(object);
			actionXYtoMove.setTarget(object);
			actionXYtoMove.setPosition(position);
			universe.setAction(actionXYtoMove);
			return;
		}	
		if(xToMove.getValue()==position.getX() && yToMove.getValue()==position.getY()){
			actionBuildStarcraftObject.setSource(object);
			actionBuildStarcraftObject.setTarget(object);
			actionBuildStarcraftObject.setPosition(position);
			actionBuildStarcraftObject.setPrice(commandCentetPrice.getValue());
			actionBuildStarcraftObject.setObjectReference(ReferenceObject.OBJECT_REFERENCE_COMMAND_CENTER1);
			universe.setAction(actionBuildStarcraftObject);
			
			isActive=false;
			}
		
	}
	

}
